home *** CD-ROM | disk | FTP | other *** search
- program Set_Time(input,output);
- {
- Version 1.03b for Turbo Pascal version 2.00b PC-DOS
-
- Program to set the system clock.
- Written and Copyright 1985 by Tim MacNary
- Permission to use is granted provided this notice remains.
-
- Included are system routines to set and get the system clock
- and to get single, non-echoed characters from the keyboard.
-
- A description of the operation of this program is part of
- procedure help.
-
- }
- const
- abort = 27; { the abort hotkey }
- toggle = 9; { toggle key for AM/PM }
- helpkey= 63; { key to display helpMsg }
- helpMsg = 'Esc to abort, Tab to toggle AM/PM, ? for help';
-
- type regtype = record
- ax,bx,cx,dx,bp,si,di,ds,es,flags:integer;
- end;
- DayType = (AM,PM);
- RangeType = set of 27..128; { the possible set of input values }
- var
- Co:integer;
- hour,min,sec,hun:byte;
- day:dayType; { AM/PM indicator }
- InputRange:RangeType; { set of acceptable keystrokes for input }
-
- procedure ReadAllChars(var InputNum:integer;var ExtendedAscii:boolean);
-
- { Get an unbuffered, single character from the keyboard using BIOS call 16H }
-
- var
- Reg:RegType;
- begin
- Reg.AX:=$0000;
- intr($16,Reg);
- if LO(Reg.AX)=00 then
- begin
- InputNum:=HI(Reg.AX);
- ExtendedAscii:=true;
- end
- else begin
- InputNum:=LO(Reg.AX);
- ExtendedAscii:=false;
- end;
- end;
-
- procedure print_Time(day:dayType;hour,min,sec,hun:byte;px,py:integer);
-
- { Print out the time, centered on line 3, then return the cursor to its
- last position. }
-
- var x,y:integer;
- begin
- x:=whereX;
- y:=whereY;
- GotoXY(px,py);
- write(hour:2,':');
- if min < 10 then write('0');
- write(min:1);
- {
- write(':');
- if sec < 10 then write('0');
- write(sec:1,'.');
- if hun < 10 then write('0');
- write(hun:1,' ');
- }
- if day = AM then write(' AM') else write(' PM');
- GotoXY(x,y);
- end;
-
- procedure Set_Time(day:dayType;hour,min,sec,hun:byte);
-
- { System routine to set the system clock. }
-
- var regs:regtype;
- begin
- regs.ax:=$2D00;
- if (day=PM) and (hour <> 12) then hour:=hour + 12;
- if (day=AM) and (hour = 12) then hour:=0;
- regs.cx:=hour * $100 + min;
- regs.dx:=(sec * $100) + hun;
- intr($21,regs);
- if lo(regs.ax) <> 0 then write('Error during set time');
- end;
-
- procedure Get_Time(var day:dayType;var hour,min,sec,hun:byte);
-
- { System routine to get the system time. }
-
- var regs:regtype;
- begin
- regs.ax:=$2C00;
- intr($21,regs);
- hour:=hi(regs.cx);
- min:=lo(regs.cx);
- sec:=hi(regs.dx);
- hun:=lo(regs.dx);
- if hour in [12..23] then day:=PM else day:=AM;
- if hour > 12 then hour:=hour - 12;
- if hour = 0 then hour := 12;
- end;
-
- procedure set_up;
- var Day:daytype;
- hour,min,sec,hun:byte;
- co:integer;
- begin
- ClrScr;
- LowVideo;
- co:=length(helpmsg);
- co:=40 - (co div 2);
- GotoXY(co,10);
- write(helpMsg);
-
- Get_Time(Day,hour,min,sec,hun);
- gotoXY(20,1); write('Current Time:');
- print_Time(Day,hour,min,sec,hun,35,1);
- NormVideo
- end;
-
- procedure help;
- var x,y:integer;
- begin
- x:=whereX; y:=whereY;
- GotoXY(1,11);
- LowVideo;
- writeln(' To set the time, three keys must be hit:one for the hour, one');
- writeln(' for the ten''s place of the minute, and one for the one''s place.');
- writeln(' Only one key is pressed for the hour; the top row of the keyboard');
- writeln(' is used as follows');
- writeln;
- NormVideo;
- writeln(' ┌───╥───╥───╥───╥───╥───╥───╥───╥───╥───╥───╥───┐');
- writeln(' │ 1 ║ 2 ║ 3 ║ 4 ║ 5 ║ 6 ║ 7 ║ 8 ║ 9 ║ 0 ║ - ║ = │');
- writeln(' └───╨───╨───╨───╨───╨───╨───╨───╨───╨───╨───╨───┘');
- writeln(' hours:1 2 3 4 5 6 7 8 9 10 11 12');
- writeln;
- LowVideo;
- writeln(' Example: The time desired is 12:03 AM. These keys must be pressed:');
- writeln(' =,0,3. If PM is needed, press the tab key.');
- writeln;
- writeln(' The Tab key toggles between AM and PM at any time; Esc aborts.');
- NormVideo;
- gotoXY(x,y);
- end;
-
- procedure Get_Input(var day:daytype;hour,min,sec,hun:integer;
- var co:integer;InputRange:RangeType);
-
- { Routine to get a single character, looping until the character is in
- the set InputRange. Additionally, toggles day between AM/PM, updating
- the time display when changed. }
-
- var extAscii:boolean;
- begin
- repeat
- ReadAllChars(co,extascii);
- if co=toggle then
- begin
- if Day = AM then Day := PM
- else Day := AM;
- print_Time(Day,hour,min,sec,hun,35,3);
- end
- else if co = helpkey then
- begin
- help;
- print_Time(Day,hour,min,sec,hun,35,3)
- end
- until (co in InputRange) and not extAscii;
- end;
-
- begin { Main Program }
- Set_Up;
- Day:=AM; hour:=0; min:=0; sec:=0; hun:=0;
- print_Time(Day,hour,min,sec,hun,35,3);
-
- InputRange:=[48..57,61,45,abort];
- gotoXY(35,4); write(' - hours ');
- Get_Input(Day,hour,min,sec,hun,co,InputRange);
- if co <> abort then
- begin
- if co in [49..57] then hour:=co - 48
- else case co of
- 48:hour:=10;
- 45:hour:=11;
- 61:hour:=12
- end;
- print_Time(Day,hour,min,sec,hun,35,3);
- InputRange:=[48..53,abort];
- gotoXY(35,4); write(' - minutes ');
- Get_Input(Day,hour,min,sec,hun,co,InputRange);
- if co <> abort then
- begin
- min:=(co - 48 ) * 10;
-
- print_Time(Day,hour,min,sec,hun,35,3);
- InputRange:=[48..57,abort];
- gotoXY(35,4); write(' - minutes ');
- Get_Input(Day,hour,min,sec,hun,co,InputRange);
- if co <> abort then
- begin
- min:=min + (co - 48);
-
- print_Time(Day,hour,min,sec,hun,35,3);
- gotoXY(34,3); write('<');gotoXY(43,3);write('>');
- gotoXY(35,4); write('Time Set ');
- gotoXY(1,9); ClrEOL;
- gotoXY(1,10); ClrEOL;
- gotoXY(1,1); ClrEOL;
- Set_Time(Day,hour,min,sec,hun);
- end
- else write('Aborted')
- end
- else write('Aborted')
- end
- else write('Aborted')
- end.